sidekiq testing 是用來在測試環境時調整 sidekiq 模式
require 'sidekiq/testing'
Sidekiq::Testing.fake! # default mode, A test fake that pushes all jobs into a jobs array
Sidekiq::Testing.inline! # An inline mode that runs the job immediately instead of enqueuing it
Sidekiq::Testing.disable! # The test harness can be disabled. Jobs are pushed to redis.
Sidekiq::Testing.fake!
非同步執行但一樣會有 jobs 速度最快
Sidekiq::Testing.inline!
立即執行不會進 redis 而且同步處理
Sidekiq::Testing.disable!
為原本的 sidekiq 默認模式,會進 redis 真的會去排隊執行
不需要另外裝 gem 已經在 Sidekiq 就有了
所以可以直接在測試下此指令指定模式
around(:example) { |example| Sidekiq::Testing.fake! { example.run } }
未完待續...
參考來源:
sidekiq官方文件
know-your-sidekiq-testing-rights